package com.sky.controller.user;


import com.sky.context.BaseContext;
import com.sky.dto.AbeibeiDTO;
import com.sky.entity.Abeibei;
import com.sky.result.Result;
import com.sky.service.AbeibeiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/abeibei")
@Api(tags = "阿贝贝接口")
@Slf4j
public class AbeibeiController {


    @Autowired
    private AbeibeiService abeibeiService;
    /**
     * 根据用户id查询阿贝贝
     * @return
     */
    @GetMapping("")
    @ApiOperation("根据用户id查询阿贝贝")
    public Result<List<Abeibei>> pagelist(){
        log.info("查询阿贝贝");
        Long userId = BaseContext.getCurrentId();
        List<Abeibei> list =abeibeiService.list(userId);
        return Result.success(list);
    }

    @PutMapping("")
    @ApiOperation("修改阿贝贝")
    public Result modify(@RequestBody AbeibeiDTO abeibeiDTO){
        log.info("修改阿贝贝:{}",abeibeiDTO);
        Long userId = BaseContext.getCurrentId();
        abeibeiService.modify(abeibeiDTO);
        return Result.success();
    }

    /**
     * 新增阿贝贝
     * @param abeibeiDTO
     * @return
     */
    @PostMapping("")
    @ApiOperation("新增阿贝贝")
    public Result add(@RequestBody AbeibeiDTO abeibeiDTO){
        log.info("新增阿贝贝:{}",abeibeiDTO);
        Long userId = BaseContext.getCurrentId();
        abeibeiService.insert(abeibeiDTO);
        return Result.success();
    }

    /**
     * 删除阿贝贝
     * @param id
     * @return
     */
    @DeleteMapping("")
    @ApiOperation("删除阿贝贝")
    public Result delete(Long id){
        log.info("删除阿贝贝：{}",id);
        abeibeiService.delete(id);
        return Result.success();
    }
}
